package com.example.znxb.zswd.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.example.znxb.zswd.entity.Infopasssword;
import com.example.znxb.zswd.service.InfopassswordService;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/zswd/infopasssword")
public class InfopassswordController {

    @Autowired
    private InfopassswordService infopassswordService;

    /**
     * 登录接口
     * @param params {"user":"用户名", "password":"密码"}
     * @return 登录结果
     */
    @PostMapping("/login")
    public Map<String, Object> login(@RequestBody Map<String, String> params) {
        String user = params.get("user");
        String password = params.get("password");
        Map<String, Object> result = new HashMap<>();
        Infopasssword loginUser = infopassswordService.login(user, password);
        if (loginUser != null) {
            result.put("success", true);
            result.put("msg", "登录成功");
            Map<String, Object> userInfo = new HashMap<>();
            userInfo.put("id", loginUser.getId());
            userInfo.put("user", loginUser.getUser());
            result.put("userInfo", userInfo);
        } else {
            result.put("success", false);
            result.put("msg", "用户名或密码错误");
        }
        return result;
    }
} 